package com.by.hellofreemarker.controller;

import com.by.hellofreemarker.entity.User;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.ArrayList;
import java.util.List;

@Controller
@RequestMapping(value = "label")
public class LabelController {

    @RequestMapping("/if")
    public String ifLabel(String username, Model model) {
        model.addAttribute("user", username);
        return "if";
    }

    @RequestMapping("/list")
    public String listLabel(int userCount, Model model) {
        List<User> users = new ArrayList<>();
        for (int i = 0; i < userCount; i++) {
            User user = new User();
            user.setName(String.format("user%d", i + 1));
            user.setAge(i + 20);
            users.add(user);
        }
        model.addAttribute("users", users);
        return "list";
    }


    @RequestMapping("/include")
    public String includeLabel(Model model) {
        return "include";
    }

}
